package cn.edu.cqu.util;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;

public class ByteFileUtil {
	public static void byteToFile(File file, byte[] by) throws IOException {
		FileOutputStream fileout = null;
		fileout = new FileOutputStream(file);
		fileout.write(by, 0, by.length);
		fileout.close();
	}

	public static byte[] fileTobyte(File file) throws IOException {
		byte[] buffer = null;
		FileInputStream fis = new FileInputStream(file);
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		byte[] b = new byte[1024];
		int n;
		while ((n = fis.read(b)) != -1) {
			bos.write(b, 0, n);
		}
		fis.close();
		bos.close();
		buffer = bos.toByteArray();
		return buffer;
	}
}
